#-*- coding: utf-8 -*-

import ConfigParser
import codecs

class FakeSecHead(object):
    def __init__(self, fp):
        self.fp = fp
        self.sechead = '[config]\n'
    def readline(self):
        if self.sechead:
            try: return self.sechead
            finally: self.sechead = None
        else: return self.fp.readline()

class config(object):
    def __init__(self, path):
        try:
            config = ConfigParser.RawConfigParser()

            config.readfp(FakeSecHead(codecs.open(path,'r','utf8')))
            self.nick1 = config.get('config', 'nick1')
            self.nick2 = config.get('config', 'nick2')
            self.logchat = config.getboolean('config', 'logchat')
            self.repeat = config.getboolean('config', 'repeat')
            self.autostop = config.getboolean('config', 'autostop')
            self.timeout = config.getint('config', 'timeout')

        except Exception, e:
            self.nick1 = u'Анон'
            self.nick2 = u'Некто'
            self.logchat = False
            self.repeat = False
            self.autostop = False
            self.timeout = 120
            print 'Error loading config.'
